#pragma once
#include <map>
#include <tinyxml/tinyxml.h>

#include "FileUtil.h"

enum ATTRTYPE
{
	NOCHANGE,
	UTF8_2_ACP,
	ACP_2_UTF8

};

class Jquery
{
private:
	TiXmlDocument m_doc;
	TiXmlDocument* m_pDoc;
	TiXmlElement* m_pRoot;


public:
	Jquery(void);
	Jquery(TiXmlElement *pEle);
	~Jquery(void);

	bool LoadFile(std::string strFile,bool bIsUtf8XML,std::string strXMLContent="");
	bool LoadDoc(TiXmlDocument& doc,std::string strFile,bool bIsUtf8XML);
	TiXmlElement* Find(std::string strSelector);
	std::list<TiXmlElement*> FindAll(std::string strSelector);
	std::list<std::string> GetSelectorParts(std::string strSelector);
	static bool Find(TiXmlElement* pEle,std::list<std::string> listSelector,std::list<TiXmlElement*>& listEle_out,bool bFindAll);
	static std::string GetNodeName(TiXmlElement* pEle);
	static bool IsAttrExist(TiXmlElement* pEle,std::string strAttr);
	static std::string GetAttr(TiXmlElement* pEle,std::string strAttr,ATTRTYPE attrType=NOCHANGE);
	static bool SetAttr(TiXmlElement* pEle,std::string strAttr,std::string strValue);
	bool SetAttr(std::string strAttr,std::string strValue);



	static std::map<std::string,std::string> GetAttrMap(std::string strSelector);
	static bool IsAttrExist(TiXmlElement* pEle,std::map<std::string,std::string> mapAttr);
	bool Parse(std::string strXMLContent,bool bIsUtf8);
	TiXmlElement* GetNode();
	bool Append(TiXmlElement* pEle);
	static bool Find(TiXmlElement* pEle, std::string strOneSelctor,const std::list<std::string>& listSubSelector,std::list<TiXmlElement*>& listEle_out,bool bFindAll);
	static std::string ToString(TiXmlElement* pEle);
	bool SaveFile(std::string strFilePath);
	bool SaveFile();
	static bool Remove(TiXmlElement* pEle);

	
	
};
